package com.mashibing.disruptor;

import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.util.DaemonThreadFactory;

import java.io.IOException;

/**
 * @author: Yuanzt
 * @Date: 2021/4/7
 */
public class Main03 {

    public static void main(String[] args) {
        int bufferSize = 1024;
        Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent::new,bufferSize, DaemonThreadFactory.INSTANCE);
        disruptor.handleEventsWith((event,sequence,endOfBatch)-> System.out.println("Event: "+event));
        disruptor.start();
        RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer();
        ringBuffer.publishEvent((event,sequence,l)->event.set(l),10000L);
        ringBuffer.publishEvent((event,sequence,l1,l2)->event.set(l1+l2),10000L,20000L);
        try {
            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
